package com.example.javaword;

import com.alibaba.fastjson2.JSONObject;
import com.deepoove.poi.XWPFTemplate;
import com.deepoove.poi.config.Configure;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

public class JsonElDemo {
    public static void main(String[] args) throws IOException {
        String jsonStr = "{\n" + "  \"songs\": [\n" + "    { \"name\": \"Memories\" },\n" + "    { \"name\": \"Sugar\" },\n" + "    { \"name\": \"Last Dance\" }\n" + "  ]\n" + "}";
        JSONObject jo = JSONObject.parse(jsonStr);
        // 开启el表达式
        Configure configure = Configure.builder().useSpringEL().build();
        XWPFTemplate template = XWPFTemplate.compile(Consts.PATH + "template_json.docx", configure).render(jo);
        template.writeAndClose(Files.newOutputStream(Paths.get(Consts.PATH + "output_json.docx")));
    }
}
